package com.tedu.stats.service.imp;

import com.tedu.stats.mapper.StatsMapper;
import com.tedu.stats.pojo.dto.StatsQuery;
import com.tedu.stats.pojo.vo.StatsVO;
import com.tedu.stats.service.StatsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class StatsServiceImp implements StatsService {
    @Autowired
    private StatsMapper statsMapper;
    @Override
    public StatsVO selectUserGrowth(StatsQuery statsQuery) {
        log.debug("获取用户增长统计业务,参数:{}", statsQuery);
        List<Map<String, Object>> resultList =statsMapper.selctUserGrowth(statsQuery);
        log.debug("获取用户增长统计业务2,结果:{}", resultList);
        StatsVO statsVO = new StatsVO();
        List<String> dates = new ArrayList<>();
        List<Integer> counts = new ArrayList<>();

        for (Map<String, Object> row : resultList) {
            dates.add((String)row.get("date"));
            Object o = row.get("count");
            Long count = (Long)o;
            Integer count1 = count.intValue();
            counts.add(count1); // 注意类型转换
        }

        statsVO.setDates(dates.toArray(new String[0]));
        statsVO.setCounts(counts.toArray(new Integer[0]));

        log.debug("获取用户增长统计业务,结果:{}", statsVO);
        return statsVO;
    }
}
